package com.hellobike.haxing.modules.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hellobike.haxing.modules.product.entity.SkuWarehouseStock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * sku仓库库存 Mapper 接口
 * </p>
 *
 * @author szzha
 * @since 2020-02-17
 */
public interface SkuWarehouseStockMapper extends BaseMapper<SkuWarehouseStock> {

    @Update("UPDATE t_sku_warehouse_stock SET stock = stock + #{changeNum},update_time=now() WHERE sku_id = #{skuId} AND stock >= 0 - #{changeNum} AND deleted = 0")
    int changeSkuWarehouseStock(@Param("skuId") Long skuId, @Param("warehouseId") Long warehouseId, @Param("changeNum") Integer changeNum);

    //允许负库存，同步wms库存需要
    @Update("UPDATE t_sku_warehouse_stock SET stock = stock + #{changeNum},update_time=now() WHERE sku_id = #{skuId} AND deleted = 0")
    int changeSkuWarehouseStockForce(@Param("skuId") Long skuId, @Param("warehouseId") Long warehouseId, @Param("changeNum") Integer changeNum);

}
